{extend name='common/container'}
{block name="content"}

<div style="margin:0 15px 15px 15px;">
	<el-card shadow="never" style="min-height:650px;">
		<div v-if="search_visible" id="search" class="search">
			<el-form ref="form" size="small" :model="searchData" inline>
				<el-form-item label="钱包地址">
					<el-input id="username" v-model="searchData.username"  style="width:150px;" placeholder="请输入钱包"></el-input>
				</el-form-item>
				<el-form-item label="状态">
					<el-select style="width:150px" v-model="searchData.status" filterable clearable placeholder="请选择">
						<el-option key="0" label="开启" value="1"></el-option>
						<el-option key="1" label="关闭" value="0"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="用户等级">
					<el-select   style="width:100%" v-model="searchData.level_id" filterable clearable placeholder="请选择用户等级">
						<el-option v-for="(item,i) in level_list" :key="i" :label="item.name" :value="item.id"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="创建时间">
					<el-date-picker value-format="yyyy-MM-dd HH:mm:ss" type="daterange" v-model="searchData.create_time" clearable range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
				</el-form-item>
				<search-tool :search_data.sync="searchData" :is_clear.sync="is_clear" @refesh_list="index"></search-tool>
			</el-form>
		</div>
		<div class="btn-group" style="margin-top:10px;margin-bottom:10px;">
			<div>
				<el-button v-for="item in button_group" :key="item.access" v-if="checkPermission(item.access,'{:implode(',',session('admin.access'))}','{:session('admin.role_id')}',[1])" :disabled="$data[item.disabled]" :type="item.color" size="mini" :icon="item.icon" @click="fn(item.clickname)">
					<span v-if="item.batch" v-text="$data['batchUpdateStatus']?'批量保存':'批量编辑'"></span>
					<span v-else v-text="item.name"></span>
				</el-button>
				                <el-link style="color: #fff" class="el-button el-button--success el-button--mini" href="/Member/diagram" aria-expanded="false">矩阵图</el-link>
				<el-link style="color: #fff" class="el-button el-button--success el-button--mini" href="/Member/recommend" aria-expanded="false">推荐图</el-link>
			</div>
			<div><table-tool :search_visible.sync="search_visible"  @refesh_list="index"></table-tool></div>
		</div>
		<el-table :row-class-name="rowClass" @selection-change="selection"  @row-click="handleRowClick"  row-key="id"  :header-cell-style="{ background: '#eef1f6', color: '#606266' }" @sort-change='sortChange' v-loading="loading"  ref="multipleTable" border class="eltable" :data="list" :summary-method="getSummaries" show-summary style="width: 100%">
			<el-table-column align="center" type="selection" width="42"></el-table-column>
			<el-table-column align="center" type = '' property="id"  label="编号"  width="70">
			</el-table-column>
			<el-table-column align="center"  property="username"  label="钱包地址">
			</el-table-column>
			<el-table-column align="center"  property="pmember"  label="上级用户"  width="">
			</el-table-column>
			<el-table-column align="center"  property="position"  label="矩阵位置">
			</el-table-column>
			<el-table-column align="center"  property="USDT"  label="USDT">
			</el-table-column>
			<el-table-column align="center"  property="power"  label="LP等级算力">
			</el-table-column>
			<el-table-column align="center"  property="LP"  label="LP矿机算力">
			</el-table-column>
			<el-table-column align="center"  property="KR"  label="KR">
			</el-table-column>
			<el-table-column align="center"  property="direct"  label="直推人数">
			</el-table-column>
			<el-table-column align="center"  property="invitation"  label="邀请码">
			</el-table-column>
			<el-table-column align="center"  property="level_name"  label="用户等级"  width="">
			</el-table-column>
<!--			<el-table-column align="center"  property="status"  label="状态"  width="90">-->
<!--				<template slot-scope="scope">-->
<!--					<el-switch @change="updateExt(scope.row,'status')" :active-value="1" :inactive-value="0" v-model="scope.row.status"></el-switch>-->
<!--				</template>-->
<!--			</el-table-column>-->
			<el-table-column align="center"  property="create_time"  label="创建时间">
				<template slot-scope="scope">
					{{parseTime(scope.row.create_time)}}
				</template>
			</el-table-column>
			<el-table-column :fixed="ismobile()?false:'right'" label="操作" align="center" width="180">
				<template slot-scope="scope">
					<div v-if="scope.row.id && scope.row.id != 1">
						<el-button v-if="checkPermission('/admin/Charitable/edit.html','{:implode(",",session("admin.access"))}','{:session("admin.role_id")}',[1])" size="mini" icon="el-icon-edit" type="primary" @click="update(scope.row)" >修改</el-button>
						<!--						<el-button v-if="checkPermission('/admin/Charitable/delete.html','{:implode(",",session("admin.access"))}','{:session("admin.role_id")}',[1])" size="mini" icon="el-icon-delete" type="danger" @click="del(scope.row)" >删除</el-button>-->
					</div>
				</template>
			</el-table-column>
		</el-table>
		<Page :total="page_data.total" :page.sync="page_data.page" :limit.sync="page_data.limit" @pagination="index" />
	</el-card>

	<!--添加-->
	<Add :show.sync="dialog.addDialogStatus" size="small" @refesh_list="index"></Add>
	<!--修改-->
	<Update :info="updateInfo" :show.sync="dialog.updateDialogStatus" size="small" @refesh_list="index"></Update>
	<!--数值加-->
	<Jia :info="jiaInfo" :show.sync="dialog.jiaDialogStatus" size="small" @refesh_list="index"></Jia>
</div>

{/block}
{block name="script"}
<script src="__PUBLIC__/assets/js/app.js"></script>
<script src="__PUBLIC__/assets/libs/xlsx/xlsx.core.min.js"></script>
<script src="__PUBLIC__/components/admin/member/add.js?v=<?php echo rand(1000,9999)?>"></script>
<script src="__PUBLIC__/components/admin/member/update.js?v=<?php echo rand(1000,9999)?>"></script>
<script src="__PUBLIC__/components/admin/member/detail.js?v=<?php echo rand(1000,9999)?>"></script>
<script src="__PUBLIC__/components/admin/member/resetPwd.js?v=<?php echo rand(1000,9999)?>"></script>
<script src="__PUBLIC__/components/admin/member/jia.js?v=<?php echo rand(1000,9999)?>"></script>
<script>
	new Vue({
		el: '#app',
		components:{
		},
		data: function() {
			return {
				dialog: {
					addDialogStatus : false,
					updateDialogStatus : false,
					detailDialogStatus : false,
					resetPwdDialogStatus : false,
					jiaDialogStatus : false,
					jianDialogStatus : false,
					importDataDialogStatus : false,
				},
				searchData:{
					username:'',
					status:'',
					level_id:'',
					create_time:''
				},
				button_group:[
					{name:'修改',color:'primary',access:'/admin/Member/update.html',icon:'el-icon-edit',disabled:'single',clickname:'update'},
					{name:'删除',color:'danger',access:'/admin/Member/delete.html',icon:'el-icon-delete',disabled:'multiple',clickname:'del'},
					{name:'修改余额',color:'primary',access:'/admin/Member/jia.html',icon:'el-icon-plus',disabled:'single',clickname:'jia'},
					{name:'导出',color:'warning',access:'/admin/Finance/dumpdata_transfer.html',icon:'el-icon-download',disabled:'',clickname:'dumpdata'},
				],
				loading: false,
				page_data: {
					limit: 20,
					page: 1,
					total:20,
				},
				level_list:<?php echo $level; ?>,
			order:'',
					sort:'',
					ids: [],
					single:true,
					multiple:true,
					search_visible:true,
					list: [],
					updateInfo:{},
			detailInfo:{},
			resetPwdInfo:{},
			jiaInfo:{},
			jianInfo:{},
			exceldata:[],
					dumppage:1,
					ws:{},
			dumpshow:false,
					percentage:0,
					filename:'',
					exceldata:[],
					dumppage:1,
					ws:{},
			dumpshow:false,
					percentage:0,
					filename:'',
					sum_amount:'',
					is_clear:false,
		}
		},
		methods:{
			index(){
				let param = {limit:this.page_data.limit,page:this.page_data.page,order:this.order,sort:this.sort}
				Object.assign(param, this.searchData,this.urlobj)
				this.loading = true
				axios.post(base_url + '/Member/index',param).then(res => {
					if(res.data.status == 200){
						this.list = res.data.data.data
						this.page_data.total = res.data.data.total
						this.loading = false
					}else{
						this.$message.error(res.data.msg);
					}
				})
			},
			updateExt(row,field){
				if(row.id){
					axios.post(base_url + '/Member/updateExt',{id:row.id,[field]:row[field]}).then(res => {
						if(res.data.status == 200){
							this.$message({message: res.data.msg, type: 'success'})
						}else{
							this.$message.error(res.data.msg)
						}
					})
				}
			},
			add(){
				this.dialog.addDialogStatus = true
			},
			update(row){
				let id = row.id ? row.id : this.ids.join(',')
				axios.post(base_url + '/Member/getUpdateInfo',{id:id}).then(res => {
					if(res.data.status == 200){
						this.dialog.updateDialogStatus = true
						this.updateInfo = res.data.data
					}else{
						this.$message.error(res.data.msg)
					}
				})
			},
			del(row){
				this.$confirm('确定操作吗?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					let ids = row.id ? row.id : this.ids.join(',')
					axios.post(base_url + '/Member/delete',{id:ids}).then(res => {
						if(res.data.status == 200){
							this.$message({message: res.data.msg, type: 'success'})
							this.index()
						}else{
							this.$message.error(res.data.msg)
						}
					})
				}).catch(() => {})
			},
			detail(row){
				this.dialog.detailDialogStatus = true
				this.detailInfo = {id:row.id ? row.id : this.ids.join(',')}
			},
			resetPwd(row){
				this.dialog.resetPwdDialogStatus = true
				this.resetPwdInfo = {id:row.id ? row.id : this.ids.join(',')}
			},
			jia(row){
				this.dialog.jiaDialogStatus = true
				this.jiaInfo = {id:row.id ? row.id : this.ids.join(',')}
			},
			importData(){
				this.dialog.importDataDialogStatus = true
			},
			dumpdata(){
				this.$confirm('确定操作吗?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.dumpshow = true
					this.confirmdumpdata()
				}).catch(() => {})
			},
			confirmdumpdata(){
				let query = {page:this.dumppage,order:this.order,sort:this.sort}
				Object.assign(query, this.searchData,{id:this.ids.join(',')},this.urlobj)
				axios.post(base_url + '/Member/dumpdata',query).then(res => {
					if(res.data.state == 'ok'){
						this.percentage = res.data.percentage
						this.dumppage = this.dumppage + 1
						this.confirmdumpdata()
					}else{
						this.dumpshow = false
						location.href = base_url + '/Member/dumpdata?state=ok&'+param(query)
					}
				})
			},
			closedialog(){
				this.dumpshow = false
			},
			closedialog(){
				this.dumpshow = false
			},
			forbidden(row){
				this.$confirm('确定操作吗?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					let ids = row.id ? row.id : this.ids.join(',')
					axios.post(base_url + '/Member/forbidden',{id:ids}).then(res => {
						if(res.data.status == 200){
							this.$message({message: res.data.msg, type: 'success'})
							this.index()
						}else{
							this.$message.error(res.data.msg)
						}
					})
				}).catch(() => {})
			},
			start(row){
				this.$confirm('确定操作吗?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					let ids = row.id ? row.id : this.ids.join(',')
					axios.post(base_url + '/Member/start',{id:ids}).then(res => {
						if(res.data.status == 200){
							this.$message({message: res.data.msg, type: 'success'})
							this.index()
						}else{
							this.$message.error(res.data.msg)
						}
					})
				}).catch(() => {})
			},
			selection(selection) {
				this.ids = selection.map(item => item.id)
				this.single = selection.length != 1
				this.multiple = !selection.length
			},
			handleRowClick(row, rowIndex,event){
				if(event.target.className !== 'el-input__inner'){
					this.$refs.multipleTable.toggleRowSelection(row)
				}
			},
			rowClass ({ row, rowIndex }) {
				for(let i=0;i<this.ids.length;i++) {
					if (row.id === this.ids[i]) {
						return 'rowLight'
					}
				}
			},
			sortChange(val){
				if(val.order == 'descending'){
					this.order= 'desc'
				}
				if(val.order == 'ascending'){
					this.order= 'asc'
				}
				this.sort = val.prop
				this.index()
			},
			getSummaries(param) {
				const { columns, data } = param;
				const sums = [];
				columns.forEach((column, index) => {
					if(index === 1) {
						sums[index] = '合计'
					}
					if(column.label === '积分') {
						sums[index] = this.sum_amount
					}
				})
				return sums
			},
			fn(method){
				this[method](this.ids)
			},
		},
		mounted(){
			this.index()
		},
	})
</script>
{/block}
